home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / info-service / gopher / Unix / GopherTools / gmail-1.01.shar / gmailbatch < prev    next >
Encoding:
Text File  |  1993-03-30  |  2.5 KB  |  99 lines

  1. #!/usr/local/bin/perl
  2. #  Change the above to point to your site's perl installation.
  3. #
  4. #  gmailbatch -- script to aid in batch submissions to gmail
  5. #
  6. #
  7. #  usage:   gmailbatch destination < inputfile
  8. #
  9. #  where "destination" is the email alias of a gmail server
  10. #
  11. #        "inputfile" is a collection of messages to be sent to gmail,
  12. #     separated by lines beginning with "%%".  The remainder of a
  13. #     "%%" line is taken to be the subject of the following message.
  14. #     If the remainder of the "%%" line is blank, then the first
  15. #     line of the message is also used as the subject.
  16. #
  17. #  Examples:
  18. #
  19. #  gmailbatch cwis@foobar.edu <<EOF
  20. #  %%About apples and oranges
  21. #  This directory contains information on apples and oranges.
  22. #  %%Apples
  23. #  Apples are red or green on the outside and white on the inside.
  24. #  Johnny Appleseed used to plant them.
  25. #  %%
  26. #  Oranges
  27. #
  28. #  Oranges are orange on the outside and divided into sections on the
  29. #  inside.  Anita Bryant used to sing about them.
  30. #  EOF
  31. #
  32. #
  33. #  gmailbatch events@foobar.edu <<EOF
  34. #  %%1993-03-17 St. Patrick's Day at the Coffeehouse
  35. #  Drink green near-beer and sing along with Toby O'Brien at the
  36. #  Coffeehouse, 8:00 p.m.
  37. #  %%1993-07-04 Independence Day fireworks at Town Lake
  38. #  Fireworks for the whole family on the lake.  Sponsored by the
  39. #  Volunteer Fire Brigade.
  40. #  EOF
  41. #
  42. #
  43. #-------------------------------------------------------------------------
  44. #
  45. #  Author: Prentiss Riddle (riddle@rice.edu).
  46. #
  47. #  History:
  48. #  02/15/93  PASR  Original version based on smug 0.1.
  49. #  
  50. #-------------------------------------------------------------------------
  51.  
  52. $separator = '%%';
  53. $sendmail = "/usr/lib/sendmail";
  54. $usage = "usage: gmailbatch destination\n";
  55.  
  56. unless ($#ARGV == 0) {
  57.     print STDERR "$usage";
  58.     exit(1);
  59. }
  60. $mailto = $ARGV[0];
  61. print "Mailing the following items to $mailto:\n";
  62.  
  63. $error = 0;
  64. $skip = 1;
  65. MAINLOOP:
  66. while (<STDIN>) {
  67.     chop;
  68.     if (/^$separator/) {
  69.         close (CURFILE) unless $skip;
  70.         s/^$separator//;
  71.         if ($_ eq "") {
  72.             # no title -- cannibalize first line of text block
  73.             $_ = <STDIN>;    # don't chop yet!
  74.             if (/^$separator/) {
  75.                 # uh-oh -- null text block
  76.                 print "Error: missing title in $dir\n";
  77.                 $error = 1;
  78.                 redo MAINLOOP;
  79.             }
  80.             chop;
  81.         }
  82.         open (CURFILE, "| $sendmail $mailto") || 
  83.             die("Couldn't open pipe to $sendmail: $!");
  84.         $skip = 0;
  85.         print CURFILE "Subject: $_\n\n";
  86.         print "$_\n";
  87.     } else {
  88.         print CURFILE $_, "\n" unless $skip;
  89.     }
  90.     
  91. } # end MAINLOOP
  92. close (CURFILE) unless $skip;
  93.  
  94. exit $error;
  95.  
  96. #------------------------------------------------------------------------
  97.  
  98. # end of gmailbatch script
  99.